apiready = function() {
seajs.use(['../../V',"../../api","../../jquery","../../app","../../service"],function(V,$api,$,app,service){
	var vm = {
		el: '.container',
	  	data: {
	  		bankList: '',
				shopId: '',
        page: 1
	  	},
	  	mounted:function() {

	  	},
	  	methods:{
				//--获取银行卡信息
				getBank: function(){
					var that = this;
					app.ajax(service['getBank'],
					{
						data: {
							values: {
								shop_code: api.pageParam.shopId,
								unionid: $api.getStorage("shop_unionid"),
							}
						}
					},
					function (res) {
						// var shopCode = res.data.shop_code; // 商店id
						if(res.code){
							api.toast({
							    msg: res.message,
							    duration: 2000,
							    location: 'bottom'
							});
						}else{
							that.bankList = res.data;
							console.log(JSON.stringify(that.bankList))
							console.log("获取支付宝信息成功!");
						}
					}
					);
				},
        addOrEditBank:function(){
          var that = this;

          var bank_name = $api.trim(this.$refs.zhi_account.value);
          var bank_user = $api.trim(this.$refs.zhi_user.value);
          var bank_phone = $api.trim(this.$refs.bank_phone.value);
          var bank_validate_code = $api.trim(this.$refs.bank_validate_code.value);
          var bank_branch_name = '';


					//--判断是否存在特殊字符
					if(app.hasSpecialChar(bank_name, '支付宝账号输入有误...', '')){
						return
					};
					if(app.hasSpecialChar(bank_user, '支付宝姓名输入有误...', '')){
						return
					};
					if(app.hasSpecialChar(bank_phone, '手机号输入有误...', 'phone')){
						return
					};


          if (bank_name == '' || bank_name == null) {
            api.toast({
                msg: '请输入支付宝账号...',
                duration: 2000,
                location: 'middle'
            });
            return;
          }
          if (bank_user == '' || bank_user == null) {
            api.toast({
                msg: '请输入支付宝姓名...',
                duration: 2000,
                location: 'middle'
            });
            return;
          }
          if (bank_phone == '' || bank_phone == null) {
            api.toast({
                msg: '请输入手机号码...',
                duration: 2000,
                location: 'middle'
            });
            return;
          }
          if (bank_validate_code == '' || bank_validate_code == null) {
						// alert("bank_validate_code: "+bank_validate_code);
            api.toast({
                msg: '请输入验证码...',
                duration: 2000,
                location: 'middle'
            });
            return;
          }

					app.ajax(service['addOrEditBank'],
					{
						data: {
							values: {
								shop_code: api.pageParam.shopId,
								unionid: $api.getStorage("shop_unionid"),
                bank_name: bank_name,
                bank_number: bank_number,
                bank_user: bank_user,
                id_card: id_card,
                bank_phone: bank_phone,
                bank_branch_name: bank_branch_name,
								code: bank_validate_code
							}
						}
					},
					function (res) {
						// var shopCode = res.data.shop_code; // 商店id
						if(res.code){
							api.toast({
									msg: res.message,
									duration: 2000,
									location: 'bottom'
							});
						}else{
							console.log("绑定银行卡成功!");
							console.log(JSON.stringify(res.data))
							alert('绑定银行卡成功!');

							api.sendEvent({
							    name: 'backtToShopIncome',
							});
							api.closeWin();

						}
					}
					);
        },
				sendCode: function(){
					var that = this;
					var bank_phone = $api.trim(this.$refs.bank_phone.value);

					if (bank_phone == '' || bank_phone == null) {
						api.toast({
								msg: '请输入手机号码...',
								duration: 2000,
								location: 'middle'
						});
						return;
					}


					app.ajax(service['smsCode'],
					{
						data: {
							values: {
								unionid: $api.getStorage("shop_unionid"),
								phone: bank_phone,
								type: 4	//0手机登录，2绑定手机号码，4绑定支付宝
							}
						}
					},
					function (res) {
						// var shopCode = res.data.shop_code; // 商店id
						if(res.code){
							api.toast({
							    msg: res.message,
							    duration: 2000,
							    location: 'bottom'
							});
						}else{
							console.log(JSON.stringify(res.code))
							console.log("获取验证码成功!");
							var i = 59;
							$(".getCode").css("display", "none")
							$(".reCode").css("display", "block")
							$(".reCode").html("重新获取验证码(60s)");
							var intervalId = setInterval(function(){
								console.log('abc');
								$(".reCode").html("重新获取验证码("+i+"s)");
								--i;
								if(i<0){
									clearInterval(intervalId)
									$(".getCode").css("display", "block")
									$(".reCode").css("display", "none")
								}
							}, 1000);
						}
					}
					);

				},

	  	},
	  	created: function(){
				var that = this;
				this.getBank();

			}
	};

	var even = function() {}
	var newVue = new Vue(vm);
	even();
});
}
